{layout name="public/layout" /}
{include file='yxnavbar'}


<div class="main">
    {include file='koi_common_nav'}
    <div class="panel panel-info">
        <div class="panel-heading">当前数量： {$page_total}</div>
        <div class="panel-body">
            <form id = "myform" action="./index.php" method="get" class="form-horizontal" role="form">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="{$_P['m']}" />
                <input type="hidden" name="do" value="{$do}" />
                <div class="form-group">
                    {if count($themelist)>1}
                    <div class="col-xs-12 col-sm-2 col-md-2">
                        <select onchange="submitForm();" class="form-control" name="themeid">
                            {loop $themelist $row}
                            <option value="{$row['id']}" {if $themeid == $row['id'] }selected="selected"{/if}>{$row['id']} - {php echo mb_substr($row['title'],0,8,'utf-8');}</option>
                            {/loop}
                        </select>
                    </div>
                    {else}
                    <input type="hidden" name="themeid" value="{$themeid}" />
                    {/if}
                    <div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
                    <span class="help-block">温馨提示：抽奖锦鲤类型 锦鲤数量 最大为5个</span>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
                        <a href="{php echo createWebUrl('koi',array('themeid'=>$themeid,'op'=>'list_add'));}" class="btn {if $op == 'list_add'}btn-primary{else}btn-default{/if}">添加锦鲤记录</a>
                        {if $show_once_add }
                        <a onclick="onceAdd()" class="btn {if $op == 'list_add'}btn-primary{else}btn-default{/if}">一键导入默认锦鲤记录</a>
                        {/if}
                    </div>
                </div>

            </form>
        </div>
    </div>

    <input type="hidden" name="current_ac" id="current_ac" value="{$ac}">
    <!--  列表框  -->
    <div class="tab-content">
        <div class="panel panel-default">
            <div class="panel-body table-responsive">
                <table class="table table-hover">
                    <thead class="navbar-inner">
                    <tr>
                        <th style="width: 50px">序号</th>
                        <th style="width: 120px">锦鲤名称</th>
                        <th style="width: 100px">锦鲤图片</th>
                        <th style="width: 80px">锦鲤类型</th>
                        <th style="width: 80px">是否为最大兑换锦鲤</th>
                        <th style="width: 120px">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $list $item}
                    <tr>
                        <td>{$item['l_id']}</td>
                        <td>{$item['title']}</td>
                        <td>
                            <a href="{php echo tomedia($item['img']);}"  target="_blank" title="查看原图">
                                <img src="{php echo tomedia($item['img']);}" style="width: 40px;height: 40px;padding: 1px;">
                            </a>
                        </td>
                        <td>{if $item['in_prize']==2}
                            <span class="label label-success">抽奖锦鲤</span>
                            {else}
                            <span class="label label-warning">兑换锦鲤</span>
                            {/if}</td>
                        <td>{if $item['is_max']==2}
                            <span class="label label-success">否</span>
                            {else}
                            <span class="label label-warning">是</span>
                            {/if}</td>
                        <td>
                            <a class="btn btn-primary btn-sm" style="width: 35px" herf="{php echo createWebUrl('koi', array('op' =>'list_edit','themeid'=>$themeid,'l_id'=>$item['l_id']));}"  title="修改信息" ><i class="fa fa-pencil-square-o"> </i></a>

                            <a class="btn btn-danger btn-sm" style="width: 35px" onclick="changeOrDelLttInfo(this)" data-type="del"  data-edit-url="" data-themeid="{$themeid}" data-id="{$item['l_id']}" title="删除奖品" data-toggle="tooltip" data-placement="top"><i class="fa fa-times"> </i></a>
                        </td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{$pager}
<script type="text/javascript">
    $(document).ready(
        function (){
        }
    );
    function submitForm(){
        var form = document.getElementById("myform");
        form.submit();
    }
    function drop_confirm(msg, url){
        if(confirm(msg)){
            window.location = url;
        }
    }
    //新增\修改奖品 提交数据
    function addOrEditLtItem() {
        if ($("#item_sort").val().length>2){
            layer.msg('奖品展示排名，请设置两位数以内的排序值');
            return;
        }
        let postUrl = "{php echo createWebUrl('lt_addoreditltitem');}";
        let success_redirect = "{php echo createWebUrl('Lt_main',array('themeid'=>$themeid));}";
        let formData = $("#form2").serialize();
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data:formData,
            success:function (e) {
                let res = e.message;
                let code = res.code;
                let msg = res.msg;
                if (code!=200){
                    layer.msg(msg)
                }else{
                    layer.msg(msg);
                    window.location.href = success_redirect;
                }

            },
            fail:function (err) {
                console.log(err)
            }
        })
    }
    // 修改、删除
    function changeOrDelLttInfo(e) {
        let l_id = e.getAttribute("data-id");
        let type = e.getAttribute("data-type");
        let themeid = e.getAttribute("data-themeid");
        let redirectUrl = e.getAttribute("data-edit-url");
        let postUrl ="";
        if (type=='edit'){
            window.location.href = redirectUrl;
        }
        if (type=='del'){
            postUrl = "{php echo createWebUrl('koi',array('op' =>'list_del'));}";
            layer.msg('您确定删除该记录吗？',{
                btn:['确定','取消'],
                yes:function (index) {
                    $.ajax({
                        url:postUrl,
                        dataType:'json',
                        method:'post',
                        data: {l_id:l_id,themeid:themeid},
                        success:function (e) {
                            let res = e.message;
                            let code = res.code;
                            let msg = res.msg;
                            if (code!=200){
                                layer.msg(msg);
                            }else{
                                layer.msg(msg);
                                location.reload();
                            }
                        },
                        fail:function (err) {
                            console.log(err)
                        }
                    });
                }
            });
        }
    }
    //一键追加默认的记录
    function onceAdd() {
        postUrl = "{php echo createWebUrl('koi',array('themeid'=>$themeid,'op'=>'list_once_add'));}";
        layer.msg('您确定添加默认记录吗？',{
            btn:['确定','取消'],
            yes:function (index) {
                $.ajax({
                    url:postUrl,
                    dataType:'json',
                    method:'post',
                    success:function (e) {
                        let res = e.message;
                        let code = res.code;
                        let msg = res.msg;
                        if (code!=200){
                            layer.msg(msg);
                        }else{
                            layer.msg(msg);
                            location.reload();
                        }
                    },
                    fail:function (err) {
                        console.log(err)
                    }
                });
            }
        });
    }
</script>
